package com.corechina.apex_osswords.common;


import com.corechina.apex_osswords.domain.vo.SysUserForTokenVo;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;

/**
 * Shiro工具类
 */
public class ShiroUtils {

	public static Session getSession() {
		return SecurityUtils.getSubject().getSession();
	}

	public static Subject getSubject() {
		return SecurityUtils.getSubject();
	}

	public static SysUserForTokenVo getUserEntity() {
		return (SysUserForTokenVo) SecurityUtils.getSubject().getPrincipal();
	}

	public static Integer getUserId() {
		return getUserEntity().getId();
	}

	public static String getUsername() {
		return getUserEntity().getUserName();
	}

	public static Integer getGroupId() {
		return getUserEntity().getGroupId();
	}

	public static Integer getSeeAll() {
		return getUserEntity().getSeeAll();
	}

	public static Integer getEnterpriseId() {
		return getUserEntity().getEnterpriseId();
	}

	public static Integer getDeptId() {
		return getUserEntity().getDeptId();
	}

	public static void setSessionAttribute(Object key, Object value) {
		getSession().setAttribute(key, value);
	}

	public static Object getSessionAttribute(Object key) {
		return getSession().getAttribute(key);
	}

	public static boolean isLogin() {
		return SecurityUtils.getSubject().getPrincipal() != null;
	}


}
